//
//  MadDebug.h
//  MadGTD
//
//  Created by Fuzhou Chen on 4/30/12.
//  Copyright (c) 2012 Fuzhou Chen. All rights reserved.
//

#ifndef MadGTD_MadDebug_h
#define MadGTD_MadDebug_h

#include <CoreFoundation/CoreFoundation.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef OSStatus MadResult;

enum {
    MAD_SUCCESS                = 0,
    MAD_ERR_BAD_PARAM          = -50,
    MAD_ERR_NO_MEMORY          = -41,
    MAD_ERR_OPEN               = -23,
    MAD_ERR_RESOURCE_NOT_FOUND = -192,
};

typedef enum {
    MINFO  = 0,
    MERROR = 1,
} MadLogLevel;

extern MadLogLevel MadGlobalLogLevel;
extern void MadCNSLog(const char* format, ...);
extern int IsFileExistInDocuments(const char* fileName);

#define MAD_CHK_PARAM(_cond, _errmsg) {\
    if (!(_cond)) {\
        MadCNSLog("[MADPARAMERR] %s:%d", __FILE__, __LINE__);\
        MadCNSLog _errmsg;\
        result = MAD_ERR_BAD_PARAM;\
        goto Exit;\
    }\
}
    
#define MAD_CHK_PARAM_OR_TERMINATE(_cond, _errmsg) {\
    if (!(_cond)) {\
        MadCNSLog("[MADPARAMERR] %s:%d", __FILE__, __LINE__);\
        MadCNSLog _errmsg;\
        exit(MAD_ERR_BAD_PARAM);\
    }\
}

#define MAD_CHK(_cond, _err, _errmsg) {\
    if (!(_cond)) {\
        MadCNSLog("[MADCHKERR  ] %s:%d", __FILE__, __LINE__);\
        MadCNSLog _errmsg;\
        result = _err;\
        goto Exit;\
    }\
}

#ifdef __cplusplus
}
#endif
#endif
